#include "s3c2440.h"
#include "timer.h"

void timer_irq(int irq) {
  static int cnt = 0;
  int tmp;

  cnt++;

  tmp = ~cnt;
  tmp &= 7;
  GPBDAT &= ~(7 << 4);
  GPBDAT |= (tmp << 4);
}

void timer_init(void) {
  TCFG0 = 99;
  TCFG1 &= ~0xf;
  TCFG1 |= 3;

  TCNTB0 = 15625;

  TCON |= (1 << 1);
  TCON &= ~(1 << 1);
  TCON |= (1 << 0) | (1 << 3);

  register_irq(10, timer_irq);
}
